package com.company.bkst.dao;

import java.util.ArrayList;

import com.company.bkst.Book;

public class BookDAO {
	
	private ArrayList<Book> book = new ArrayList<Book>();

	public BookDAO(){
		this.book.add(new Book("00001", "RESTful Web Services", "Leonard Richardson", 
				"978-0596529260", 50.00));
		this.book.add(new Book("00002", "RESTful Web Services Cookbook: Solutions for Improving Scalability and Simplicity", "Subbu Allamaraju", 
				"978-0596801687", 45.00));
		this.book.add(new Book("00003", "APIs: A Strategy Guide", "Daniel Jacobson", 
				"978-1449308926", 21.52));
		this.book.add(new Book("00004", "Scrum: a Breathtakingly Brief and Agile Introductionn", "Chris Sims", 
				"978-1937965044", 8.96));
		this.book.add(new Book("00005", "Getting Started with OAuth 2.0", "Ryan Boyd", 
				"978-1449311605", 20.13));
	}
		
	public BookDAO(Book book){
		this.book.add(book);
	}

	public ArrayList<Book> getAllBooks(){
		return book;
	}
	
	public Book getBook(String bookID){
        for(Book book: this.book){
            if(book.getBookId().equals(bookID)){
               return book;
            }
        }

        return null;
	}
	
	public ArrayList<Book> getBookByTitle(String title){
		ArrayList<Book> book_results = new ArrayList<Book>();
        for(Book book: this.book){
            if(book.getTitle().toLowerCase().contains(title.toLowerCase())){
               book_results.add(book);
            }
        }

        return book_results;
	}
	
	public ArrayList<Book> getBookByAuthor(String author){
		ArrayList<Book> book_results = new ArrayList<Book>();
        for(Book book: this.book){
            if(book.getAuthor().toLowerCase().contains(author.toLowerCase())){
               book_results.add(book);
            }
        }

        return book_results;
	}
}
